package com.example.traccarmanager.slice;

import com.example.traccarmanager.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.TextField;
import ohos.data.DatabaseHelper;
import ohos.data.preferences.Preferences;

public class MainAbilitySlice extends AbilitySlice {
    public static final String PREFERENCE_URL = "url";
    private TextField textField;

    /**
     *
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_fragment_start);
        textField = (TextField) findComponentById(ResourceTable.Id_field_server);
        DatabaseHelper databaseHelper = new DatabaseHelper(getContext());
        Preferences preferences = databaseHelper.getPreferences("test");
        String value = preferences.getString(PREFERENCE_URL, "null");
        if (value != null && !value.equals("null")) {
            intent.setParam("urls",textField.getText());
            present(new MainFragmentSlice(), intent);
        } else {
            intent.setParam("urls",textField.getText());
            present(new StartFragmentSlice(), intent);
        }

    }

    /**
     *
     */
    @Override
    public void onActive() {
        super.onActive();
    }

    /**
     *
     */
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
